local paoluo = fk.CreateSkill {
  name = "lingling__paoluo",
}

Fk:loadTranslationTable{
  ["lingling__paoluo"] = "炮烙",
  [":lingling__paoluo"] = "出牌阶段限一次，你可以将一张牌当不能被【无懈可击】响应的【火攻】使用，对目标造成伤害后其减1点体力上限，"..
  "你获得其展示牌。",

  ["#lingling__paoluo"] = "炮烙：将一张牌当【火攻】使用，若对目标造成伤害，其减体力上限且你获得其展示的牌",
}

paoluo:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  prompt = "#lingling__paoluo",
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("fire_attack")
    card.skillName = paoluo.name
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    use.disresponsiveList = table.simpleClone(player.room.players)
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(paoluo.name, Player.HistoryPhase) == 0
  end,
})

paoluo:addEffect(fk.Damage, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and data.card and table.contains(data.card.skillNames, paoluo.name) and
      player.room.logic:damageByCardEffect() and (not data.to.dead or not player.dead)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if not data.to.dead then
      room:changeMaxHp(data.to, -1)
    end
    if data.to ~= player and not player.dead then
      local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if use_event then
        local use = use_event.data
        if table.contains(use.card.skillNames, paoluo.name) then
          local dat = use.extra_data and use.extra_data.lingling__paoluo or {}
          if dat[data.to] then
            local cards = table.filter(dat[data.to], function (id)
              return table.contains(data.to:getCardIds("h"), id)
            end)
            if #cards > 0 then
              room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, paoluo.name, nil, true, player)
            end
          end
        end
      end
    end
  end,
})

paoluo:addEffect(fk.CardShown, {
  can_refresh = function(self, event, target, player, data)
    if target == player then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if e then
        return table.contains(e.data.card.skillNames, paoluo.name)
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data
      use.extra_data = use.extra_data or {}
      use.extra_data.lingling__paoluo = use.extra_data.lingling__paoluo or {}
      use.extra_data.lingling__paoluo[player] = use.extra_data.lingling__paoluo[player] or {}
      table.insertIfNeed(use.extra_data.lingling__paoluo[player], data.cardIds[1])
    end
  end,
})

paoluo:addAI(nil, "vs_skill")

return paoluo
